﻿using System;
using System.Windows.Data;
using System.Globalization;

namespace Silverlight.ControlToolkit.Converters
{
    public class MonthConverter : IValueConverter
    {

        private string[] arrMonths = new string[] { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };

        public object Convert(object value,
                             Type targetType,
                             object parameter,
                             CultureInfo culture)
        {
            int intIndex = (int)value;

            if (intIndex >= arrMonths.GetLowerBound(0) && intIndex <= arrMonths.GetUpperBound(0))
                return arrMonths[(int)value];
            else
                return "";
        }

        public object ConvertBack(object value,
                                  Type targetType,
                                  object parameter,
                                  CultureInfo culture)
        {

            if (Array.IndexOf<string>(arrMonths, value.ToString()) >= 0)
                return Array.IndexOf<string>(arrMonths, value.ToString());
            else
                return 0;
        }

    }

}
